package sctu.edu.java.year2016.team04.baiyunfei.day20160623;

import java.util.Scanner;

/**
 * 建Computer类，该类中有一个计算最大公约数的方法，如果向该方法传递负整数，该方法就会抛出自定义异常
 * Created by DE on 2016/6/23.
 */
public class Computer {
    public int num;

   public  int count(int a,int b) throws NewException{
       int remainder,temp=0;                 //余数
       int min,max;
       min=a<b?a:b;
       max=a>b?a:b;
       remainder=max%min;

       if(a<0||b<0){
throw new NewException(a,b);
       }
else{           //辗转相除法
           while(remainder==0){
 temp =remainder;
           remainder=min%remainder;
           min=temp;

}


       }

       return temp;
   }

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        Computer computer=new Computer();
        System.out.println("请输入要计算公约数的两个数：");
        int a= scanner.nextInt();
        int b= scanner.nextInt();
        try {
            computer.count(a,b);
        } catch (NewException e) {
            e.printStackTrace();
        }

     //   System.out.println("最大公约数为：" + "computer.count(a,b)");
    }
}